package com.aj.activity.dialog;

import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.aj.activity.R;

public class ChooseChineseZodiacDialog extends BaseDialog implements
		OnWheelChangedListener {
	private WheelView chinese_zodiac;

	private TextView cannel_button;
	private TextView sure_button;
	private String[] mchinese_zodiacData;
	private String chineseZodiac;
	private TextView dialog_title;
	private IChineseZodiac chooseChineseZodiac;
	private String kinds;

	public IChineseZodiac getChooseDay() {
		return chooseChineseZodiac;
	}

	public void setChineseZodiac(IChineseZodiac chineseZodiac) {
		this.chooseChineseZodiac = chineseZodiac;
	}

	public interface IChineseZodiac {
		public void chooseChineseZodiacSuccess(String chineseZodiac);

		public void chooseConstellationSuccess(String constellation);
	}

	public ChooseChineseZodiacDialog(Context context, String kinds) {
		super(context, R.layout.dialog_date);
		this.kinds = kinds;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_chinese_zodiac);

		chinese_zodiac = (WheelView) findViewById(R.id.id_chinese_zodiac);
		ButtonClickEvent buttonClickEvent = new ButtonClickEvent();
		cannel_button = (TextView) findViewById(R.id.cannel_button);
		dialog_title = (TextView) findViewById(R.id.dialog_title);
		sure_button = (TextView) findViewById(R.id.sure_button);
		cannel_button.setOnClickListener(buttonClickEvent);
		sure_button.setOnClickListener(buttonClickEvent);
		if (kinds.equals("1")) {
			dialog_title.setText("选择生肖");
			initChineseDatas();
		} else {
			dialog_title.setText("选择星座");
			initDatas();
		}
		chinese_zodiac.setViewAdapter(new ArrayWheelAdapter<String>(context,
				mchinese_zodiacData));

		chinese_zodiac.addChangingListener(this);

		chinese_zodiac.setVisibleItems(5);

	}

	class ButtonClickEvent implements android.view.View.OnClickListener {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.cannel_button:
				dismiss();
				break;
			case R.id.sure_button:
				if (chooseChineseZodiac != null) {
					if (kinds.equals("1")) {
						chooseChineseZodiac
								.chooseChineseZodiacSuccess(mchinese_zodiacData[chinese_zodiac
										.getCurrentItem()]);
					} else {
						chooseChineseZodiac
								.chooseConstellationSuccess(mchinese_zodiacData[chinese_zodiac
										.getCurrentItem()]);
					}
				}
				dismiss();
				break;
			}
		}
	}

	private void initChineseDatas() {
		mchinese_zodiacData = new String[12];
		mchinese_zodiacData[0] = "鼠";
		mchinese_zodiacData[1] = "牛";
		mchinese_zodiacData[2] = "虎";
		mchinese_zodiacData[3] = "兔";
		mchinese_zodiacData[4] = "龙";
		mchinese_zodiacData[5] = "蛇";
		mchinese_zodiacData[6] = "马";
		mchinese_zodiacData[7] = "羊";
		mchinese_zodiacData[8] = "猴";
		mchinese_zodiacData[9] = "鸡";
		mchinese_zodiacData[10] = "狗";
		mchinese_zodiacData[11] = "猪";
	}

	private void initDatas() {
		mchinese_zodiacData = new String[12];
		mchinese_zodiacData[0] = "白羊座";
		mchinese_zodiacData[1] = "金牛座";
		mchinese_zodiacData[2] = "双子座";
		mchinese_zodiacData[3] = "巨蟹座";
		mchinese_zodiacData[4] = "狮子座";
		mchinese_zodiacData[5] = "处女座";
		mchinese_zodiacData[6] = "天秤座";
		mchinese_zodiacData[7] = "天蝎座";
		mchinese_zodiacData[8] = "射手座";
		mchinese_zodiacData[9] = "摩羯座";
		mchinese_zodiacData[10] = "水瓶座";
		mchinese_zodiacData[11] = "双鱼座";
	}

	@Override
	public void onChanged(WheelView wheel, int oldValue, int newValue) {
	}
}
